<!DOCTYPE html>
<html lang="en">
<!--<script src="myscript.js"></script>-->
<head>
    <meta charset="UTF-8">
    <title>js类型转换</title>
    <script type="text/javascript">

        document.write("<h1> 这是一个简介 </h1>")
        document.write("<h1> 这也是一个简介 </h1>")

    </script>

    <script>
        var a = "hello world"
        var b = "nice javascript"
        var c = "nice java"
        var str = "python|java|js|php"
        var big = "HELLO WORLD"
        var num = 1
        var g = "   hello world 1   "
        var strNum = "123455"
        var strNumFloat = "123.11"
        var dict = {first: 1, second: 2, third: 3}
        var myList = [1, 2, 3]

        var mydate = new Date()

        function retLog(msg) {
            console.log(msg)
        }

        /* 时间 转换 */
        retLog(mydate.getDay())  // 获取一周中的某天 0-6
        retLog(mydate.getTime()) // 13位时间戳
        retLog(mydate.getFullYear()) // 获取年
        retLog(mydate.getMonth())  // 获取月-1
        retLog(mydate.getDate()) // 获取日
        retLog(mydate.getHours()) // 获取小时
        retLog(mydate.getMinutes()) // 获取分钟
        retLog(mydate.getSeconds()) // 获取秒
        retLog(mydate.getMilliseconds()) // 获取毫秒

        /* 字符串转数字*/
        retLog(Number(strNum)) // 123455
        retLog(Number("")) // 0
        retLog(Number("11 22")) // NaN
        retLog(parseInt(strNum)) // 123455
        retLog(parseFloat(strNumFloat)) // 123.11


        /* 一元运算符 + */
        retLog(+strNum)  // 123455

        /* 布尔转数字 */
        retLog(Number(false)) // 0
        retLog(Number(true)) // 1
        retLog(Number(1 > 0)) // 1

        /* 日期转数字 */
        retLog(Number(mydate)) // 等价于 mydate.getTime()

        /* 自动转换为字符串 */
        retLog(dict.toString())  // [object, object]
        retLog(myList.toString()) // 1,2,3
        retLog(mydate.toString()) // Fri Jan 17 2025 11:05:34 GMT+0800 (中国标准时间)




    </script>
</head>
<body>
<button type="button" onclick="alert('hello world')">点击我</button>
</body>
</html>